package com.riven.bilibilidemo.adapter;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.nostra13.universalimageloader.core.ImageLoader;
import com.riven.bilibilidemo.R;
import com.riven.bilibilidemo.bean.BangumiBean;

import java.util.List;

/**
 * Created by Pooh on 2017/3/10.
 */
public class MyRecycleAdapter extends RecyclerView.Adapter<MyRecycleAdapter.MyViewHodler> {
    Context context;
    List<BangumiBean.ResultBean> recy_bean;

    public MyRecycleAdapter(Context context) {
        this.context = context;
    }

    @Override
    public MyViewHodler onCreateViewHolder(ViewGroup parent, int viewType) {
        View view= LayoutInflater.from(context).inflate(R.layout.recycle_group_item,parent,false);
        MyViewHodler hodler = new MyViewHodler(view);
        return hodler;
    }

    @Override
    public void onBindViewHolder(MyViewHodler holder, int position) {
        holder.recycle_name.setText(recy_bean.get(position).getSerializing().get(position).getTitle());
        holder.recycle_new.setText(recy_bean.get(position).getSerializing().get(position).getNewest_ep_index());
        ImageLoader.getInstance().displayImage(recy_bean.get(position).getSerializing().get(position).getCover(),holder.recycle_img);
        Log.i("aaa", "onBindViewHolder: 0000....."+recy_bean.get(position).getSerializing().get(position).getTitle());
    }

    @Override
    public int getItemCount() {
        return recy_bean==null?0:recy_bean.size();
    }


    public class MyViewHodler extends RecyclerView.ViewHolder {

        private final ImageView recycle_img;
        private final TextView recycle_new;
        private final TextView recycle_name;

        public MyViewHodler(View itemView) {
            super(itemView);
            recycle_name = (TextView) itemView.findViewById(R.id.recycle_name);
            recycle_new = (TextView) itemView.findViewById(R.id.recycle_new);
            recycle_img = (ImageView) itemView.findViewById(R.id.recycle_img);
        }
    }
}
